package com.develop.controller;

import java.util.Arrays;

import com.develop.annotation.Login;
import com.develop.annotation.LoginUser;

import com.develop.entity.UserEntity;
import com.develop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.develop.common.utils.R;



/**
 * 用户
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-05-27 16:17:05
 */
@RestController
@RequestMapping("api/user")
public class UserController {
    @Autowired
    private UserService userService;


    /**
     * 信息
     */
    @RequestMapping("/info")
    @Login
    public R info(@LoginUser UserEntity loginUser){
        UserEntity user = userService.getById(loginUser.getId());

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody UserEntity user){


        userService.updateById(user);

        return R.ok();
    }



    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] ids){
        userService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
